Skip to content

feat(grok): multi-agent visibility via task.* events - #5425

Closed
EnzoTironi wants to merge 5 commits into
pingdotgg:mainfrom
EnzoTironi:pr/grok-multiagent
Closed

feat(grok): multi-agent visibility via task.* events#5425
EnzoTironi wants to merge 5 commits into
pingdotgg:mainfrom
EnzoTironi:pr/grok-multiagent

Conversation

@EnzoTironi

@EnzoTironi EnzoTironi commented Aug 5, 2026

Copy link
Copy Markdown

What Changed

Map Grok in-process subagent tools (spawn_subagent and relatives) to T3 task.started / task.completed so multi-agent work is visible like Claude Task tools.

Stacked on #5424. Fixes #5420

Why

Live grok agent stdio emits tool_call title spawn_subagent with completed status and subagent_id (verified 2026-08-05). V1 deliberately ignored child sessions (#3156); product still needs parent-turn visibility of spawned work without flattening child transcripts.

UI Changes

Uses existing task/work-log surfaces — no new components. Visibility of subagent rows in the thread timeline.

Checklist

  • This PR is small and focused — tip still carries stack; multi-agent delta alone is small
  • I explained what changed and why
  • Timeline screenshot of spawn_subagent to task row
  • Video N/A

Known review findings (must fix — real bugs)

  • HIGH: task.* reuses the tool-call event stamp → same eventId → activity PK collision drops the task row
  • MED: every pending/inProgress update re-emits task.started (need per-taskId guard)
  • MED: isGrokSubagentToolCall matches substring subagent in title/detail (prefer structured tool name)

Test plan

  • Detector unit tests
  • Live probe: spawn_subagent tool_call shape matches detector

Model: grok-4.5 (Grok Build)


Note

Medium Risk
Large Grok adapter and provider snapshot changes affect runtime events and composer behavior; reviewers flagged possible task/tool eventId collisions and subagent detector false positives.

Overview
Grok spawn_subagent (and similar) tool calls now emit task.started / task.completed on the parent turn so multi-agent work shows up in existing task/work-log UI, with per-toolCallId dedupe for started/completed.

The diff is a broader Grok ACP alignment with live grok agent stdio: ACP session updates for reasoning chunks, usage, available commands, config options, and session titles; token usage from usage_update and prompt result _meta; /compactthread.state.changed compacted; plan mode via /plan prefix, exit_plan_mode capture, and plan.md tool writes → turn.proposed.completed; mid-thread model/reasoning via session/set_model _meta.reasoningEffort and CLI spawn flags (no forced new thread); slash/skills catalog pushed from initialize/available_commands_update through GrokDriver snapshot streams; provider snapshot adds static /compact, reasoning effort options, and updated Grok presentation flags.

The mock ACP agent and tests cover unsolicited JSON-RPC ids, init commands, compact, session info, usage meta, and the new adapter paths.

Reviewed by Cursor Bugbot for commit 3929597. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add multi-agent task visibility and reasoning effort support to the Grok provider via task.* events

  • Emits task.started and task.completed runtime events for Grok subagent tool calls, surfacing multi-agent activity in the thread UI.
  • Adds reasoning effort support: spawns Grok with --reasoning-effort, passes _meta.reasoningEffort through session/set_model, and exposes a Reasoning select option in model capabilities when advertised by ACP.
  • Parses availableCommands from ACP initialize result to populate slash commands and skills (including a static /compact command always present in the menu).
  • Emits thread.token-usage.updated events from both live UsageUpdated ACP events and prompt RPC _meta, with granular input/output/cached/reasoning token breakdowns and maxTokens from model context windows.
  • Handles x.ai/session_notification with auto_compact_completed to emit thread.state.changed with compacted details, and session_info_update to emit thread.metadata.updated when the session title changes.
  • Adds plan mode support: injects /plan prefix when interactionMode is plan, captures plan.md writes and x.ai/exit_plan_mode calls to surface proposed-plan cards.
  • Behavioral Change: requiresNewThreadForModelChange is now false and showInteractionModeToggle is now true for the Grok provider presentation.

Macroscope summarized 3929597.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e217416-eaa6-4142-b701-a64ec8e6b0a9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Aug 5, 2026
Comment thread apps/server/src/provider/Layers/GrokAdapter.ts Outdated
Comment thread apps/server/src/provider/Drivers/GrokDriver.ts
Comment thread apps/server/src/provider/acp/GrokAcpSupport.ts
Comment thread apps/server/src/provider/Layers/GrokProvider.ts Outdated
Comment thread apps/server/src/provider/Layers/GrokAdapter.ts
Comment thread apps/server/src/provider/Layers/GrokAdapter.ts
Comment thread apps/server/src/provider/Layers/GrokAdapter.ts
@macroscopeapp

macroscopeapp Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

1 blocking correctness issue found. This PR introduces significant new Grok functionality including multi-agent task visibility, plan mode handling, and token usage tracking across multiple files. The scope qualifies as a new feature requiring human review, and there are unresolved comments identifying potential bugs in context window handling and subagent event sequencing.

You can customize Macroscope's approvability policy. Learn more.

@EnzoTironi

Copy link
Copy Markdown
Author

Review findings from Bugbot/Macroscope for this slice are fixed on the Zoen product tip (zoen/main @ 16474ab0d). Will restack / re-push these PR heads after further slim-slicing. Open remaining: effort restart without session.exited (or adopt #5403 set_model path).

Shared AcpRuntimeModel/CoreRuntimeEvents/SessionRuntime and xAI
extension hooks used by the Grok adapter (and related fixtures).
Grok driver/adapter/provider core: slash catalog, process-scoped
effort, usage meter, auth surface, set_model. Plan toggle and
multi-agent task mapping land in later stack layers.
@EnzoTironi

Copy link
Copy Markdown
Author

Closing: multi-agent task.* mapping is included in #5423 with stamp uniqueness + dedupe fixes. Issue #5420 remains linked from #5423.

@EnzoTironi EnzoTironi closed this Aug 5, 2026
Comment on lines +380 to +390
ingest(input.sessionModels?.availableModels);
const initializeModelState = input.initializeMeta?.modelState;
if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {
const availableModels = initializeModelState.availableModels.flatMap((entry) => {
if (!isRecord(entry) || typeof entry.modelId !== "string") {
return [] as Array<{ modelId: string; _meta?: unknown }>;
}
return [{ modelId: entry.modelId, _meta: entry._meta }];
});
ingest(availableModels);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium Layers/GrokAdapter.ts:380

buildGrokModelContextWindows ingests session model state first, then unconditionally ingests initialize metadata into the same Map, so an initialize entry with the same modelId overwrites the authoritative session value. When the two context-window values differ, downstream code reads the stale initialize value and reports an incorrect context limit. Ingest initialize data first, or skip keys already set from session state.

Suggested change
ingest(input.sessionModels?.availableModels);
const initializeModelState = input.initializeMeta?.modelState;
if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {
const availableModels = initializeModelState.availableModels.flatMap((entry) => {
if (!isRecord(entry) || typeof entry.modelId !== "string") {
return [] as Array<{ modelId: string; _meta?: unknown }>;
}
return [{ modelId: entry.modelId, _meta: entry._meta }];
});
ingest(availableModels);
}
ingest(input.sessionModels?.availableModels);
const initializeModelState = input.initializeMeta?.modelState;
if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {
const availableModels = initializeModelState.availableModels.flatMap((entry) => {
if (!isRecord(entry) || typeof entry.modelId !== "string") {
return [] as Array<{ modelId: string; _meta?: unknown }>;
}
return [{ modelId: entry.modelId, _meta: entry._meta }];
});
for (const model of availableModels) {
const id = model.modelId.trim();
if (!id || windows.has(id)) continue;
const tokens = totalContextTokensFromMeta(model._meta);
if (tokens !== undefined) {
windows.set(id, tokens);
}
}
}
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/provider/Layers/GrokAdapter.ts around lines 380-390:

`buildGrokModelContextWindows` ingests session model state first, then unconditionally ingests initialize metadata into the same `Map`, so an initialize entry with the same `modelId` overwrites the authoritative session value. When the two context-window values differ, downstream code reads the stale initialize value and reports an incorrect context limit. Ingest initialize data first, or skip keys already set from session state.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3929597. Configure here.

payload: event.rawPayload,
},
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed-only subagent lacks start

Medium Severity

Live Grok often reports spawn_subagent only as completed, but this path emits task.completed without a preceding task.started. Projection titles completed tasks from the started description, so the computed title is unused and multi-agent rows show without a useful name—the common live case called out in the PR.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3929597. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grok provider: multi-agent visibility via task.* events

1 participant